package edu.ssdut.revise.models;

import com.github.javaparser.ast.body.Parameter;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class VisParamNode extends VisBaseNode {
    private final List<String> annotations;
    private final String type;
    private final String identifier;
    //private final List<String> modifiers;

    public VisParamNode(Parameter param) {
        super(param);
        this.annotations = param.getAnnotations().stream().map(Objects::toString).collect(Collectors.toList());
        this.type = param.getTypeAsString();    //TODO: generics 在这里所有的泛型都会变成字符串（比如泛型的泛型），不是很好的解决方案
        this.identifier = param.getNameAsString();
        //为什么在JavaParser Parameter中会有modifiers
        //this.modifiers = param.getModifiers().stream().map(Objects::toString).collect(Collectors.toList());
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (annotations.size() > 0) {
            for (String annotation : annotations) {
                sb.append(annotation).append(" ");
            }
        }
        sb.append(type).append(" ");
        sb.append(identifier);
        return sb.toString();
    }

    @Override
    public String getTypeName() {
        return "ParamNode";
    }

    public List<String> getAnnotations() {
        return annotations;
    }

    public String getType() {
        return type;
    }

    public String getIdentifier() {
        return identifier;
    }
}
